//
//  DDDefaultsAvatarView.m
//  DingDongZP
//
//  Created by Ray on 16/4/12.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDDefaultsAvatarView.h"

@implementation DDDefaultsAvatarView

- (void)awakeFromNib
{
//    [super awakeFromNib];
    self.floatShow = YES;
    self.popDirection = CCPopoverFromBottom;
    self.width = [UIScreen mainScreen].bounds.size.width;
    
    float x = 20;
    float y = 10;
    float space = 10;
    float width = (self.width - 2*x - 3*10) / 4;
    
    NSArray *btnImgNames;
    if ([DDClientInfoManager clientType] == DDClientTypeBoss){
    
     btnImgNames = @[@"b1", @"b2", @"b3", @"b4", @"b5", @"b6", @"b7", @"b8"];
    }else{
    
     btnImgNames = @[@"c1", @"c2", @"c3", @"c4", @"c5", @"c6", @"c7", @"c8"];
    }

    
    for (int i = 0; i < 8 && i < btnImgNames.count;  i++) {
        UIButton *btn = [self createBtn];
        btn.frame = CGRectMake(x, y, width, width);
        NSString *img = btnImgNames[i];
        [btn setBackgroundImage:[UIImage imageNamed:img]  forState:UIControlStateNormal];
        [self addSubview:btn];
        
        btn.tag = 100 + i;
        
        x += width + space;
        if (i == 3) {
            x = 20;
            y += width + space;
        }
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = width/2;
    }
}

- (UIButton *)createBtn
{
    UIButton *btn = [UIButton new];
    [btn addTarget:self action:@selector(actionBtn:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

- (void)actionBtn:(UIButton *)btn
{
    NSArray *btnImgNames;
    if ([DDClientInfoManager clientType] == DDClientTypeBoss){
        
        btnImgNames = @[@"b1", @"b2", @"b3", @"b4", @"b5", @"b6", @"b7", @"b8"];
    }else{
        
        btnImgNames = @[@"c1", @"c2", @"c3", @"c4", @"c5", @"c6", @"c7", @"c8"];
    }
    NSString *imgname = [btnImgNames objectAtIndex:btn.tag-100];
    if (self.didGetImage) {
        self.didGetImage([UIImage imageNamed:imgname]);
    }
    [self dismissWithAnimation:YES];
}

- (IBAction)cancelBtn:(id)sender {
    
    [self dismissWithAnimation:YES];
}

@end
